import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const stores = new Vuex.Store({
    state:{
        blockid:null,           //楼栋ID
        unit:'',              //存储默认小区
        cellid:null,             //切换默认管理需要用到此ID
        userid:null,            //存储用户id
        username:'全部',                    //刚登录单元列表时默认为全部
        unitsid:null,               //切换小区时需要用到此ID
    },
    mutations:{
        login(state,item){                              //登录时的数据管理
            let that = this;
            if(item.defaultBlock !== undefined){
                state.blockid = item.defaultBlock.blockId;    
                state.userid = item.id;
                state.unit = item.defaultBlock.fullName;
                state.cellid = item.defaultBlock.id;
            }else{
                state.unit = '用户暂未绑定小区';
            }
        },

        cell(state,item){                           //切换单元时的管理
            state.unit = item.fullName;
            state.blockid = item.blockId;
            state.cellid = item.id;
        },

        units(state,item){
            // console.log(item)
            state.username = item.name;
            state.unitsid = item.id;
        },
        repeat(state){
            state.username = '全部';
            state.unitsid = 0;
        }
    }
})

export const store = stores;